package cn.tedu.api;
/**本类用于练习字符串的拼接*/
public class TestString3 {
    public static void main(String[] args) {
        String s = "abcdefghigklmnopqrstuvwxyz";
//        method1(s);//使用方式1拼接字符串
        method2(s);
    }

    private static void method2(String s) {
//        StringBuffer sb = new StringBuffer();
        StringBuilder sbr2 = new StringBuilder();
        long t1 = System.currentTimeMillis();
        for (int i = 0; i <10000 ; i++) {
            //使用工具类的append()对字符串s进行拼接
//            sb.append(s);
            sbr2.append(s);
        }
        long t2 = System.currentTimeMillis();
//        System.out.println(sb);
        System.out.println(sbr2);
        System.out.println(t2-t1);
    }

    private static void method1(String s) {
        String result = "";
        long t1 = System.currentTimeMillis();//计时功能
        for (int i = 0; i <10000 ; i++) {
            result = result + s;
        }
        long t2 = System.currentTimeMillis();
        System.out.println(result);
        System.out.println(t2-t1);
    }
}
